<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="copyright" content="www.apicloud.com" />
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>舆情处置完毕</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.css" />

	<style>
		html {
			height: 100%;
		}

		body {
			height: 100%;
			width: 100%;
		}

		input {
			height: 50px;
			font-size: 18px;
			color: #8E8C8C;
			width: 80%;
		}

		input::-webkit-input-placeholder {
			color: #ccc;
		}
		/* 头部样式 */

		#header {
			border-bottom: 1px solid #8E8C8C;
		}

		.topbar {
			height: 50px;
			border-bottom: 1px solid #DDDFE3;
		}

		#title {
			color: #333;
		}

		.back {
			float: left;
			padding-right: 30px;
		}

		.back img {
			height: 30px;
			margin-top: 10px;
			margin-left: 10px;
			margin-bottom: 10px;
		}

		.topbar .title {
			line-height: 50px;
			font-size: 20px;
			position: absolute;
			left: 50%;
			-webkit-transform: translateX(-50%);
			transform: translateX(-50%);
		}
		/* 内容样式 */

		#main {
			width: 100%;
			height: 100%;
			margin: 0px;
			padding: 0px;
		}

		#main .select {
			width: 100%;
			text-align: left;
			font-size: 1.3em;
			color: #333;
		}

		#main .option {
			width: 90%;
			margin: 0px 5%;
			margin-top: 20px;
			font-weight: bold;
		}

		#main .option .radio {
			width: 40%;
			font-size: 1em;
			font-weight: normal;
			padding: 5px 10px;
		}

		#radio_1 {
			width: 50%;
			text-align: center;
			background: #3A8B7A;
			color: #fff;
			border-radius: 5px 0px 0px 5px;
		}

		#radio_2 {
			width: 50%;
			text-align: center;
			background: #e0e0e0;
			border-radius: 0px 5px 5px 0px;
		}

		.condition {
			width: 90%;
			margin: 10px 5%;
			padding: 0px;
			font-size: 1em;
		}

		.condition>ul {
			line-height: 36px;
		}

		.condition>ul>li {
			width: 100%;
			text-indent: 1em;
		}

		.condition .right {
			float: right;
			margin-right: 5%;
			display: none;
		}

		#measures {
			width: 95%;
			margin: 5px 5px 5px 5px;
			border: 1px solid #e0e0e0;
			border-radius: 5px;
			padding: 2px;
			line-height: 26px;
		}

		#feedback {
			width: 95%;
			margin: 5px 5px 5px 5px;
			border: 1px solid #e0e0e0;
			border-radius: 5px;
			padding: 2px;
			line-height: 26px;
		}
		/*.email, .passwd, .btn {margin:3px 10px;}*/

		.btn {
			margin: 3px 10px;
		}

		.btn {
			background: #3A8B7A;
			color: #fff;
			height: 40px;
			text-align: center;
			line-height: 40px;
			font-size: 20px;
			border-radius: 5px;
		}
		/* 底部样式 */

		.bottom {
			/*position: absolute;bottom: 0;*/
			width: 100%;
			height: 50px;
			text-align: center;
			/*padding-bottom: 20px;*/
			font-size: 12px;
		}

		input {
			outline: none;
		}
	</style>
</head>

<body>
	<div class="top">
		<div id="main">
			<input type="hidden" id="area_id" name="area_id" value="0">
			<div class="select" style="background-color:#fff">
				<div class="option">真实性：(必选)</div>
				<div class="condition">
					<input type="hidden" id="isreal" name="isreal" value="0">
					<ul>
						<li id="selected_1" onclick="openSelect(1)">完全属实<b id="duigou_1" class="right">√</b></li>
						<li id="selected_2" onclick="openSelect(2)">部分属实<b id="duigou_2" class="right">√</b></li>
						<li id="selected_3" onclick="openSelect(3)">不属实<b id="duigou_3" class="right">√</b></li>
					</ul>
				</div>
				<div class="option">处置结果：(必选)</div>
				<div class="condition" style="text-align:center;width: 95%; margin:10px 10px;">
					<textarea style="overflow:scroll;font-size:16px;" id="measures" name="measures" cols="28%" rows="12"></textarea>
				</div>
				<input type="hidden" id="is_media" name="is_media" value="1">
				<div class="option">媒体反馈：(必选)<span class="radio"><span id="radio_1" onclick="openRadio(1)">有</span><span id="radio_2" onclick="openRadio(2)">无</span></span>
				</div>
				<div class="condition" style="text-align:center;width: 95%; margin:10px 10px;">
					<textarea style="overflow:scroll;font-size:16px;" id="feedback" name="feedback" cols="28%" rows="5"></textarea>
				</div>
			</div>
			<ul id='ul_imgList' class="aui-list-view aui-grid-view">
				<li style="text-align：center;" class="aui-list-view-cell aui-img aui-col-xs-6" onclick="goto_AddImageFunNew();">
					<img style="height:180px；width:auto;border: 1px #cdcdcd solid;" class="aui-img-object" src="../image/img-more2.png">
				</li>
			</ul>
		</div>
		<div id="clear_5"></div>
		<div id="btn_tj" class="btn" tapmode="buyhover" onclick="goto_SubmitDataFun()">提 交</div>
		<!-- <div style="font-size:14px;margin:5px">
			1、区县级处置人点击“提交”后，等待市级处置人审核后状态改为“处置完毕”。<br/> 2、市级处置人点击“提交”后，可以直接设置状态为“处置完毕”。
		</div> -->
	</div>

	<!---------------------------底部信息------------------------------------->
	<div class="bottom">

	</div>
	<!---------------------------底部信息------------------------------------->
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/alpenlicebe.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hashes.min.js"></script>
<script type="text/javascript">
	function goto_open_permission(perm) {
		var perms = new Array();
		perms.push(perm);
		var has = api.hasPermission({
			list: perms
		});
		if (!has || !has[0] || !has[0].granted) {
			// api.confirm({
			// 	title: '提醒',
			// 	msg: "没有开启相机权限,\n是否前往设置?",
			// 	buttons: ['去设置', '取消']
			// }, function(ret, err) {
			// 	if (1 == ret.buttonIndex) {
			api.requestPermission({
				list: perms,
				code: 100001
			}, function(ret, err) {
				var str = '请求结果：\n';
				str += '请求码: ' + ret.code + '\n';
				str += "是否勾选\"不再询问\"按钮: " + (ret.never ? '是' : '否') + '\n';
				str += '请求结果: \n';
				var list = ret.list;
				for (var i in list) {
					str += list[i].name + '=' + list[i].granted + '\n';
				}
				apialert(str);
				console.log(JSON.stringify(ret));
			});
			// 	}
			// });
			return false;
		}
		return true;
	}

	function goto_AddImageFunNew() {
		var perms = new Array();
		perms.push("storage");
		perms.push("camera");
		var rets = api.hasPermission({
			list: perms
		});
		var perms_add = new Array();
		$.each(rets, function(index, v) {
			if (!v.granted) {
				perms_add.push(v.name);
			}
		});
		if (perms_add.length != 0) {
			var perms_add_str = '';
			for (var i = 0; i < perms_add.length; i++) {
				if (perms_add[i] == 'storage') {
					perms_add_str += "存储,";
				}
				if (perms_add[i] == 'camera') {
					perms_add_str += "相机,";
				}
			}
			perms_add_str = (perms_add_str.substring(perms_add_str.length - 1) == ',') ? perms_add_str.substring(0, perms_add_str.length - 1) : perms_add_str;
			api.confirm({
				title: '提醒',
				msg: "需要开启" + perms_add_str + "权限,请前往设置",
				buttons: ['去设置', '取消']
			}, function(ret, err) {
				if (1 == ret.buttonIndex) {
					api.requestPermission({
						list: perms_add,
						code: 100001
					}, function(ret, err) {
						// var str = '请求结果：\n';
						// str += '请求码: ' + ret.code + '\n';
						// str += "是否勾选\"不再询问\"按钮: " + (ret.never ? '是' : '否') + '\n';
						// str += '请求结果: \n';
						var list = ret.list;
						var perms_false = new Array();
						for (var i in list) {
							// str += list[i].name + '=' + list[i].granted + '\n';
							if (!list[i].granted) {
								perms_false.push("list[i].name");
							}
						}
						if (perms_false.length == 0) {
							goto_AddImageFun();
						}
					});
				}
			});

		} else {
			goto_AddImageFun();
		}

	}

	function goto_AddImageFun() {
		api.confirm({
			title: "系统提示",
			msg: "您想要从哪里选取图片 ?",
			buttons: ["拍照", "相册", "取消"]
		}, function(ret, err) {
			var sourceType = "album";
			if (1 == ret.buttonIndex) {
				sourceType = "camera";
			} else if (2 == ret.buttonIndex) {
				sourceType = "album";
			} else {
				return;
			}
			api.getPicture({
				sourceType: sourceType,
				encodingType: 'jpg',
				mediaValue: 'pic',
				destinationType: 'url',
				/*url\base64*/
				targetWidth: 720,
				targetHeight: 1280,
				saveToPhotoAlbum: true
			}, function(ret_img, err_img) {
				if (ret_img) {
					if ('' == ret_img.data) {
						api.alert({
							title: '系统提示',
							msg: '没有选择照片'
						});
						return;
					}
					api.showProgress({
						style: 'default',
						animationType: 'fade',
						title: '',
						text: '',
						modal: true
					});
					var MD5 = new Hashes.MD5;
					var access_token = Alpe_getLocalStorge("access_token");
					var admin_id = Alpe_getLocalStorge("admin_id");
					var sign = MD5.hex(access_token + admin_id + 'datas/getMsg1.0syjqingbao');

					var url = Alpe_ApiUrl + 'r=datas/UpPic&access_token=' + access_token + '&admin_id=' + admin_id +
						'&v=1.0&sign=' + sign;
					console.log(url);
					api.ajax({
						url: url,
						method: 'post',
						cache: false,
						timeout: 30,
						dataType: 'json',
						returnAll: false,
						data: {
							values: {
								name: 'alpenlicebe'
							},
							files: {
								file: ret_img.data
							}
						}
					}, function(ret_up, err_up) {
						console.log($api.jsonToStr(err_up));
						console.log($api.jsonToStr(ret_up));
						if (ret_up) {
							if ("100" == ret_up.success) {
								api.toast({
									msg: '上传成功',
									duration: 2000,
									location: 'middle'
								});
								var html = "<li class='aui-list-view-cell aui-img aui-col-xs-6' style='position: relative;text-align: center;margin: 0 auto'>" +
									"<input class='alpenlicebe_20151204_hf_img_list' type='hidden' value='" + ret_up.pic_path + "'/>" +
									"<img style='height:180px' class='aui-img-object' src='" + ret_up.pic_path_show + "'> " +
									"<div style='text-align: center; padding-top: 5px; position: absolute;z-index: 999;top: 130px; left: 10px; bottom: 0; right: 0;'>" +
									"<button onclick=goto_AddImageFun_show('" + ret_up.pic_path_show + "'); style='width:48%;' class='aui-btn aui-btn-primary'>查看</button>" +
									"<button onclick=goto_AddImageFun_delete(this); style='width:48%;' class='aui-btn aui-btn-danger'>移除</button>" +
									"</div>" +
									"</li>";
								$("#ul_imgList").prepend(html);
								api.hideProgress();
							} else {
								api.alert({
									title: '系统提示',
									msg: ret_up.message
								});
								api.hideProgress();
							}
						} else {
							api.alert({
								msg: ('错误码：' + err_up.code + '；错误信息：' + err_up.msg + '网络状态码：' + err_up.statusCode)
							});
							api.hideProgress();
						};
					});
				} else {
					api.alert({
						title: '系统提示',
						msg: err_img.msg
					});
				}
			});
		});
	}

	function goto_AddImageFun_show(imgUrl) {
		var obj = api.require('imageBrowser');
		obj.openImages({
			imageUrls: [imgUrl],
			showList: false,
			activeIndex: 0
		});
	}

	function goto_AddImageFun_delete(obj) {
		$(obj).parent().parent().remove();
	}
	apiready = function() {
		goto_loadInfoDetailFun();
	}

	function goto_loadInfoDetailFun() {
		var infoID = api.pageParam.infoID;
		if ('' == infoID || undefined == infoID || null == infoID) {
			api.alert({
				title: '系统提示',
				msg: '参数错误'
			});
			return;
		}
		api.showProgress({
			style: 'default',
			animationType: 'fade',
			title: '',
			text: '',
			modal: false
		});

		var MD5 = new Hashes.MD5;
		var access_token = Alpe_getLocalStorge("access_token");
		var admin_id = Alpe_getLocalStorge("admin_id");
		var sign = MD5.hex(access_token + admin_id + infoID + 'datas/getMsg1.0syjqingbao');

		var url = Alpe_ApiUrl + 'r=datas/getMsg&access_token=' + access_token + '&admin_id=' + admin_id +
			'&message_id=' + infoID +
			'&v=1.0&sign=' + sign;
		api.ajax({
			url: url,
			method: 'get',
			cache: false,
			timeout: 30,
			dataType: 'json'
		}, function(ret, err) {
			if (ret) {
				if ("100" == ret.success) {
					if (ret.isreal == "1" || ret.isreal == "2" || ret.isreal == "3") {
						openSelect(ret.isreal);
					}
					$("#measures").val(ret.deal_result);
					// alert(ret.forwarding_area_id);
					$("#area_id").val(ret.forwarding_area_id);
					if (ret.is_media == "2") {
						openRadio(ret.is_media);
					}
					$("#feedback").val(ret.feedback);

					/*deal_status=1 forwarding_status=0  处置中未转办区县
						deal_status=1 forwarding_status=1  处置中已转办区县，区县未提交
						deal_status=1 forwarding_status=2  处置中转办区县，并且区县已提交
						deal_status=2 forwarding_status=3  处置完毕
					*/


					$("#btn_tj").html("提交");
					$.each(ret.img_path, function(index, v) {
						var html = "<li class='aui-list-view-cell aui-img aui-col-xs-6' style='position: relative;text-align: center;margin: 0 auto'>" +
							"<input class='alpenlicebe_20151204_hf_img_list' type='hidden' value='" + v.img_path + "'/>" +
							"<img style='height:180px' class='aui-img-object' src='" + v.img_path_show + "'> " +
							"<div style='text-align: center; padding-top: 5px; position: absolute;z-index: 999;top: 130px; left: 10px; bottom: 0; right: 0;'>" +
							"<button onclick=goto_AddImageFun_show('" + v.img_path_show + "'); style='width:48%;' class='aui-btn aui-btn-primary'>查看</button>" +
							"<button onclick=goto_AddImageFun_delete(this); style='width:48%;' class='aui-btn aui-btn-danger'>移除</button>" +
							"</div>" +
							"</li>";
						$("#ul_imgList").prepend(html);
					});

					api.hideProgress();
					// if (ret.deal_status == 0) {
					// 	api.closeFrame();
					// 	api.closeWin();
					// 	api.alert({
					// 		title: '系统提示',
					// 		msg: '请先设置“处置中”'
					// 	});
					// }
				} else {
					api.alert({
						title: '系统提示',
						msg: ret.message
					});
					api.hideProgress();
				}
				api.hideProgress();
			} else {
				api.alert({
					title: '系统提示',
					msg: '错误码：' + err.code + '；错误信息：' + err.msg + '网络状态码：' + err.statusCode
				});
				api.hideProgress();
			}
		});
	}

	//选中真实性
	function openSelect(id) {
		//将之前选中的样式复原
		var selected_id = document.getElementById('isreal').value;
		if (selected_id != "0") {
			document.getElementById('duigou_' + selected_id).style.display = "none";
			document.getElementById('selected_' + selected_id).style.background = "#fff";
			document.getElementById('selected_' + selected_id).style.color = "#333";
		}

		//标记处已选中的样式
		if (id != selected_id) {
			document.getElementById('duigou_' + id).style.display = "block";
			document.getElementById('selected_' + id).style.background = "#e0e0e0";
			document.getElementById('selected_' + id).style.color = "#3A8B7A";
			document.getElementById('isreal').value = id;
		} else {
			document.getElementById('isreal').value = "0";
		}
	}

	//选中有无媒体反馈
	function openRadio(id) {
		//将之前选中的样式复原
		var selected_id = document.getElementById('is_media').value;
		if (selected_id != "0") {
			document.getElementById('radio_' + selected_id).style.background = "#e0e0e0";
			document.getElementById('radio_' + selected_id).style.color = "#333";
		}
		//标记处已选中的样式
		if (id != selected_id) {
			document.getElementById('radio_' + id).style.background = "#3A8B7A";
			document.getElementById('radio_' + id).style.color = "#fff";
			//输出已选中的
			document.getElementById('is_media').value = id;
		} else {
			document.getElementById('is_media').value = "0";
		}
	}

	function goto_SubmitDataFun() {
		var infoID = api.pageParam.infoID;
		if ('' == infoID || undefined == infoID || null == infoID) {
			api.alert({
				title: '系统提示',
				msg: '参数错误4'
			});
			return;
		}
		/*获取上传图片列表*/
		var imgList = "";
		$('.alpenlicebe_20151204_hf_img_list').each(function(index) {
			imgList += $(this).val() + '|';
		});
		//console.log(imgList);

		var measures = $("#measures").val();
		var deal_status = "2";
		var feedback = $("#feedback").val();
		var is_media = $("#is_media").val();
		var isreal = $("#isreal").val();
		if (isreal == '0') {
			api.alert({
				title: '系统提示',
				msg: '真实性不能为空'
			});
			return;
		}
		if (measures == '') {
			api.alert({
				title: '系统提示',
				msg: '处置结果不能为空'
			});
			return;
		}
		//      if(feedback=='' || document.getElementById('is_media').value == "有"){
		//       	api.alert({title:'系统提示',msg:'媒体反馈不能为空'});
		//			return;
		//      }

		if (document.getElementById('is_media').value == "1") {
			if (feedback == '') {
				api.alert({
					title: '系统提示',
					msg: '媒体反馈不能为空'
				});
				return;
			}

		}
		api.confirm({
			title: '确认是否提交',
			msg: '提交成功后将返回原信息页面，可返回列表查看提交信息。',
			buttons: ['确定', '取消']
		}, function(ret, err) {
			if (ret.buttonIndex == 1) {
				api.showProgress({
					style: 'default',
					animationType: 'fade',
					title: '',
					text: '',
					modal: false
				});

				var MD5 = new Hashes.MD5;
				var access_token = Alpe_getLocalStorge("access_token");
				var admin_id = Alpe_getLocalStorge("admin_id");
				var sign = MD5.hex(access_token + admin_id + infoID + 'datas/setResult1.0syjqingbao');

				/*var url = Alpe_ApiUrl+'r=datas/setResult&access_token='+access_token+'&admin_id='+admin_id
					+'&message_id='+infoID
					+'&imgList='+imgList
					+'&feedback='+feedback
					+'&is_media='+is_media +'&isreal='+isreal
					+'&area_id=-99&deal_status='+deal_status
					+'&measures='+measures +'&deal_result='+measures
					+'&v=1.0&sign='+sign; */
				var area_id = $("#area_id").val();
				var url = Alpe_ApiUrl + 'r=datas/setResult&access_token=' + access_token + '&admin_id=' + admin_id +
					'&message_id=' + infoID +
					'&is_media=' + is_media + '&isreal=' + isreal +
					'&area_id=' + area_id + '&deal_status=11' +
					'&v=1.0&sign=' + sign;
				console.log(url);
				var pap = {
					imgList: imgList,
					feedback: feedback,
					measures: measures,
					deal_result: measures
				};
				//console.log(url);
				//console.log($api.jsonToStr(pap));
				api.ajax({
					url: url,
					method: 'post',
					cache: false,
					returnAll: false,
					data: {
						values: pap
					},
					dataType: 'json'
				}, function(ret, err) {
					console.log($api.jsonToStr(ret));
					if (ret) {
						api.hideProgress();
						api.toast({
							msg: ret.message,
							duration: 2000,
							location: 'middle'
						});
						if (ret.success == "101") {
							/*注册已经处理的事件，刷新详细页面*/
							api.sendEvent({
								name: 'Alpe_Event_yq_dosomething',
								extra: {
									keyID: 'alpenlicebe'
								}
							});
							setTimeout(function() {
								api.closeWin();
							}, 900);
						}
					} else {
						api.alert({
							title: '系统提示',
							msg: '错误码：' + err.code + '；错误信息：' + err.msg + '网络状态码：' + err.statusCode
						});
						api.hideProgress();
					}
				});
			}
		});
	}
</script>

</html>
